home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 54 / utl / li.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-09-18  |  19.1 KB  |  807 lines

  1. /*
  2.              FOLLOW THESE INSTRUCTIONS AND DELETE THIS SECTION
  3.  
  4.  
  5.  
  6. LI.HLP - ASSISTANCE IN COMPILING AND LINKING THIS PROGRAM
  7.  
  8.  
  9. Enter an editor with the LI.C program source downloaded, extract each
  10. of the modules (perform a search for these keywords):
  11.  
  12.        LI.C
  13.        LI.LNK
  14.        SORT.C
  15.        TMLIB.C
  16.  
  17.  
  18. Compile them.
  19.  
  20. Link them together with the supplied link file.
  21. Select the LINK.TTP program and enter "-WITH LI.LNK".
  22.  
  23. Remember to check the .C file and .LNK files for the locations of libraries,
  24. as mine are all in drive C: (a 500K ramdisk).
  25.  
  26. It only takes me 1:52 to compile and link (includes ramdisk program/library
  27. load times).
  28. */
  29.  
  30. /*   LI.C            V2.0
  31.  
  32.         List files, size, date and time
  33.  
  34.     V1.3 upgrades:
  35.  
  36.         SORT filenames, correct exiting after no files found
  37.  
  38.     V1.4 upgrades:
  39.  
  40.         correct reporting of filetype, use library modules for
  41.         date/time/numeric conversions
  42.  
  43.     V2.0 upgrades:
  44.  
  45.         output now defaults to screen instead of printer,
  46.         parse command switch "/OUTPUT" to direct output to screen,
  47.         parse "/SORT" and "/NOSORT" switches to list files by when
  48.         added to directory by DOS
  49.  
  50.   (c) COPYRIGHT 1986 BY THOMAS J. MYNAR
  51.   THIS SOFTWARE MAY BE COPIED AND DISTRIBUTED FREELY WITH THE
  52.   INCLUSION OF THIS NOTICE.  NO WARRANTY AND/OR USEABILITY IS
  53.   IMPLIED.
  54.  
  55. */
  56.  
  57. #include <c:gemlib.h>
  58. #include <c:stdio.h>
  59. #include <c:osbind.h>
  60.  
  61. #define    DAPRT 0
  62. #define    MAXFILE 140
  63. #define    MAXLEN    54
  64. #define PRT    1
  65. #define CON    2
  66. #define TRUE    1
  67. #define FALSE    0
  68.  
  69. int    maxlen, srtlen;
  70. char    COPYRIGHT[]  =    { "\15\12Copyright \275 1986 Tom Mynar\277\15\12\
  71. Directory program  V" },
  72.     VERSION[] =    { "2.0 " },
  73.     e_fmt1[14] =    { "\12\12\15Total of " },
  74.     e_fmt2[12] =    { " files, in " },
  75.     e_fmt3[20] =    { " bytes, matching " },
  76.     e_maxfil[40]=    {"\12\15Maximum files found, sorry, missing: " },
  77.     cr_lfs[8] =    { "\12\12\15" },
  78.     errntf[18] =    { "\12\15File not found" },
  79.     prsank[18] =    { ", press any key" },
  80.     hdr[56]    =    { "\12\15    FILENAME      SIZE       DATE     TIME  \
  81. FLAGS\12\15" },
  82.     srnend[8] =    { "\12\15Done" },
  83.     tos[20] =    { "\12\15Enter Filespec: " },
  84.     r_w_flag[8] =    { " R/x\12\15" },
  85.     am_pm_str[6] =    { " xm" };
  86. char    dta[44], dirspec[64], out_buff[132], dirlst[MAXLEN*MAXFILE],
  87.     fmt_num[10], fmt_nam[14], fmtdat[12], fmttim[12], cmnd[255],
  88.     cmnval[255];
  89. char    *filename, *at_buff, *at_fmt, *at_nam, *at_srch, *at_bu2, *datstr,
  90.     *timstr;
  91. long    error, filesize, tot_siz, tot_fil, F_SUBDIR = 0x1F;
  92. int    waitans, done, sizsrch, noopt, noval, outdev, wntsrt, swpos, nextsw;
  93. short int    readonly = 0x01, subdir = 0x10, allfile = 0x00; vollab = 0x08;
  94. short int    attribute, drive_no, lincnt;
  95. unsigned short int    date, time, index;
  96.  
  97. /*
  98.    put one char to printer
  99. */
  100. static void putlst(c)
  101. char c;
  102. {    Bconout(DAPRT, c); }
  103.  
  104. /*
  105.    Put a null terminated string to the printer
  106. */
  107. static void prtstr(s)
  108. char *s;
  109. {    if    (outdev == PRT)
  110.     {    while (*s) putlst(*s++); }
  111.     else
  112.     {    if    (outdev == CON)
  113.         {    Cconws( s );    }
  114.     }
  115. }
  116.  
  117. /*
  118.    function to decode the DTA into file specifications of name
  119.    size, date, time and attribute 
  120. */
  121. dec_file()
  122. {
  123. char        one_char[2];
  124. long int    PS_date, PS_time;
  125.  
  126.     at_bu2 = &fmt_num[0]; filesize = *(long*) (&dta[26]);
  127.     lngstr( at_bu2, filesize );
  128.     strfil( at_bu2, at_bu2, 0x09, " " );
  129.     filename = &dta[30];
  130.     one_char[1] = dta[21];
  131.     one_char[0] = '\0';
  132.     attribute = *(short int *) (&one_char[0]);
  133.     date = *(short int *) (&dta[24]);
  134.     time = *(short int *) (&dta[22]);
  135.     datstr = &fmtdat[0];
  136.     timstr = &fmttim[0];
  137.     PS_date = date; cnvdate( datstr, PS_date, 0x00 );
  138.     PS_time = time; cnvtime( timstr, PS_time, 0x00 );
  139. }
  140.  
  141. /*
  142.    save filename, get next filename
  143. */
  144.  
  145. static void loop()
  146. {
  147.     done = 0;
  148. /*
  149.    until end of file searches matching
  150. */
  151.     while    (done == 0)
  152.     {    dec_file();
  153.  
  154.         for (index=MAXLEN-10;index<=130;index++) out_buff[index]='\0';
  155.         for (index=0;index<=MAXLEN-10;index++)   out_buff[index]=' ';
  156.  
  157. /*
  158.    determine if sub directory or not (affects filename printing)
  159. */
  160.         if    ( (attribute & subdir) == subdir )
  161.         {    at_buff=&out_buff[1];    strcpy( at_buff, filename );
  162.             at_bu2=&out_buff[15];    strcpy( at_bu2, "<DIR>");
  163. /*
  164.    put the filename at char pos 1
  165.    put the text "DIR" where size goes
  166. */
  167.         }
  168.         else
  169.         {    if    ( (attribute & vollab) == vollab )
  170.             {    at_buff=&out_buff[0];
  171.                 strcpy( at_buff, filename );
  172.                 at_bu2=&out_buff[15];    strcpy( at_bu2, "<LABEL>");
  173. /*
  174.    put filename at beginning
  175.    put the text "LABEL" where size goes
  176. */
  177.              }
  178.           else
  179.             {    at_buff=&out_buff[3];
  180.                             strcpy( at_buff, filename ); at_buff=&out_buff[15];
  181.                 at_bu2=&fmt_num[0]; strcpy( at_buff, at_bu2 );
  182. /*
  183.    put filename right shifted
  184. */
  185.             }
  186.         }
  187.  
  188. /*
  189.    determine read/write or read/only flag
  190.    add put string together with all substrings formatted
  191. */
  192.         if    (attribute & readonly)
  193.         {    r_w_flag[3] = 'O'; } /* read only */
  194.         else
  195.         {    r_w_flag[3] = 'W'; } /* read/write */
  196.         for (index=1;index<=24;index++)
  197.             {if (out_buff[index]==0) {out_buff[index]=' ';}}
  198.         at_buff = &out_buff[26]; strncpy( at_buff, datstr, 0x09 );
  199.         out_buff[35] = ' ';
  200.         at_buff = &out_buff[36]; strncpy( at_buff, timstr, 0x08 );
  201.         at_buff = &out_buff[44]; at_bu2=&r_w_flag[0]; strcpy( at_buff, at_bu2 );
  202.         lincnt = lincnt+1;
  203.         if    (lincnt == MAXFILE)
  204.         {    Cconws( e_maxfil ); Cconws( filename );
  205.             Cconws( "\12\15" ); lincnt = lincnt-1;
  206.         }
  207. /*
  208.    append current line to buffer, go for next file
  209. */
  210.         at_buff = &out_buff[0];
  211.         at_bu2=&dirlst[(lincnt-1)*MAXLEN]; dirlst[(lincnt-1)*MAXLEN]='\0';
  212.         strcpy( at_bu2, at_buff );
  213.         tot_siz = tot_siz + filesize;
  214.         tot_fil = tot_fil + 1;
  215.         index = Dsetdrv( drive_no ); error = Fsnext();
  216.         if    (error == -49)
  217.         {    done = -1; /* end loop */ }
  218.         else
  219.         {    if    (error < 0 )
  220.             {    rpterr( "F_NEXT", error );
  221.             }
  222.         }
  223.     }
  224. }
  225.  
  226. /* MAIN LOOP */
  227.  
  228. main( argc, argv )
  229. int  argc;
  230. char *argv[];
  231. {    appl_init();     /* Set the system up to do GEM calls */
  232.  
  233.     if    (argc != 2) /* print header if entry with no parms */
  234.     {    at_buff = ©RIGHT[0]; Cconws( at_buff );
  235.         at_buff = &VERSION[0];   Cconws( at_buff );
  236.     }
  237.     error = Fsetdta(dta);   /* setup data area */
  238.     if    (error < 0)
  239.     {    rpterr( "F_SETDTA", error );
  240.     }
  241.  
  242. while    (0 == 0) /* forever */
  243. {    lincnt  = 0; tot_siz = 0; tot_fil = 0;
  244.     for (index=0;index<=131;index++) out_buff[index]='\0';
  245.     for (index=0;index<=63;index++)  dirspec[index]='\0';
  246.  
  247. /*
  248.   ask user for filename specification and look for the first file
  249. */
  250.     at_fmt = &tos[0]; Cconws( at_fmt );
  251.     if    (argc == 2)
  252.     {    at_buff = &out_buff[2]; out_buff[2] = '\0';
  253.         strcpy( at_buff, argv[1] ); Cconws( at_buff );
  254.     }
  255.     else
  256.     {    at_buff = &out_buff[0]; out_buff[0] = '\62';
  257.         Cconrs( at_buff );
  258.     }
  259.  
  260. /*
  261.    see if a drive specified or set to active
  262. */
  263.     if    (out_buff[3] == ':')
  264.     {    drive_no = 1;
  265.         drive_no <<= ((out_buff[2] || 40) - 'a');
  266.     }
  267.     else
  268.     {    drive_no = Dgetdrv();
  269.     }
  270. /*
  271.    decode all switches passed (/O redirect output, /N /S sort toggle)
  272. */
  273.     outdev = CON; wntsrt = TRUE;
  274.     nextsw = getsw( at_buff, cmnd, cmnval );
  275.     if    (noopt == 0)
  276.     {    swpos = pos( at_buff, "/", 0x0 ); *(at_buff+swpos)='\0';
  277.         done = FALSE;
  278.         while    (done == FALSE)
  279.         {
  280.             if    (cmnd[0] == 'N') wntsrt = FALSE;
  281.             if    (cmnd[0] == 'S') wntsrt = TRUE;
  282.             if    (cmnd[0] == 'O') /* output command ? */
  283.             {    if    (noval)  /* no value, make it screen */
  284.                 {    outdev = CON;
  285.                 }
  286.                 else
  287.                 {    if    (cmnval[0] == 'P')
  288.                     {    outdev = PRT;
  289.                     }
  290.                     if    (cmnval[0] == 'C')
  291.                     {    outdev = CON;
  292.                     }
  293.                 }
  294.             }
  295.             at_buff = at_buff + nextsw - 1;
  296.             nextsw = getsw( at_buff, cmnd, cmnval );
  297.             if    (noopt != 0)
  298.             {    done = TRUE;
  299.             }
  300.             else
  301.             {    at_buff = at_buff + nextsw - 1;
  302.             }
  303.         }
  304.     }
  305.     at_buff = &out_buff[2]; at_bu2 = &dirspec[0]; strcpy( at_bu2, at_buff );
  306.  
  307. /*
  308.   search for the first folder
  309. */
  310.     index = Dsetdrv( drive_no ); error = Fsfirst( at_buff, F_SUBDIR );
  311. /*    set drive, get first file ****** BUG HERE, should only get dirs */
  312.     if    (error < 0)
  313.     {    if    (error != -33)
  314.         {    rpterr( "F_SFIRST", error );
  315.         }
  316.         else
  317.         {    at_buff = &errntf[0]; Cconws( at_buff );
  318.             at_buff = &prsank[0]; Cconws( at_buff );
  319.             waitans = getch();
  320.             if    (argc == 2)
  321.             {    exit(0);
  322.             }
  323.             /* tell user the end */
  324.         }
  325.     }
  326.     else
  327.     {
  328.  
  329. /*
  330.    print header to printer, lookup and decode filenames
  331. */
  332.         at_fmt = &hdr[0];
  333.         prtstr( at_fmt );
  334.         loop();
  335.         if    (wntsrt == TRUE)
  336.         {    maxlen = MAXLEN;
  337.             srtlen = 14;
  338.             SORT( &dirlst[0], lincnt-1, maxlen, srtlen );
  339.         }
  340. /*
  341.    print all filenames
  342. */
  343.         for (index=0;index<lincnt;index++)
  344.         {    at_buff=&dirlst[(index)*MAXLEN]; prtstr( at_buff );
  345.         }
  346. /*
  347.    print totals, ask if we continue now
  348. */
  349.         at_fmt = &e_fmt1[0]; prtstr( at_fmt );
  350.         at_buff = &out_buff[0]; lngstr( at_buff, tot_fil );
  351.         prtstr( at_buff ); at_fmt = &e_fmt2[0]; prtstr( at_fmt );
  352.         at_buff = &out_buff[0]; lngstr( at_buff, tot_siz );
  353.         prtstr( at_buff ); at_fmt = &e_fmt3[0]; prtstr( at_fmt );
  354.         at_srch = &dirspec[0]; prtstr( at_srch );
  355.         at_bu2  = &cr_lfs[0];  prtstr( at_bu2 );
  356.         at_buff = &srnend[0]; /* tell user we're done */
  357.         if    (argc != 2)   /* if entry with a command */
  358.         {    Cconws( at_buff ); at_buff = &prsank[0];
  359.             Cconws( at_buff ); waitans = getch();
  360.             if    ( waitans == 3  )/*  exit if CTRL/C */
  361.                 exit(0);
  362.         }
  363.         else
  364.         {    exit(0);
  365.         }
  366.     }
  367. } /* end of forever */
  368. } /* end of main */
  369.  
  370. /*
  371.  
  372. *
  373. * LI.LNK - Control file for linking C:LI.BIN
  374. *
  375. * Step 1 - initialization
  376. * =======================
  377. *
  378. * C initialization must be included first.
  379. *
  380. INPUT   c:\startup.bin
  381. *
  382. * Step 2 - user modules
  383. * =====================
  384. *
  385. INPUT c:\LI
  386. INPUT c:\TMLIB
  387. INPUT c:\SORT
  388. *
  389. * Step 3 - C library
  390. * ==================
  391. *
  392. * C library - must always be included.
  393. *
  394. LIBRARY c:\clib.bin
  395. *
  396. * Step 4 - GEM graphics library
  397. * =============================
  398. *
  399. * GEM graphics library
  400. *
  401. LIBRARY c:\gemlib.bin
  402. *
  403.  
  404. */
  405.  
  406.  
  407. /*   SORT.C            V1.0
  408.  
  409.     Sort array passed
  410.  
  411.     Calling format:
  412.  
  413.         SORT(    CHAR *pointer to string array,
  414.             INT # elements,
  415.             INT maximum length of string,
  416.             INT maximum number of characters to compare
  417.              )
  418.  
  419.  
  420.   (c) COPYRIGHT 1986 BY THOMAS J. MYNAR
  421.   THIS SOFTWARE MAY BE COPIED AND DISTRIBUTED FREELY WITH THE
  422.   INCLUSION OF THIS NOTICE.  NO WARRANTY AND/OR USEABILITY IS
  423.   IMPLIED.
  424.  
  425. */
  426.  
  427. extern void SORT( dirlst, lincnt, maxlen, match_len )
  428. char    *dirlst;
  429. int    lincnt, maxlen, match_len;
  430. {
  431. int flag_word, swapped;
  432. unsigned short int    jindex, index;
  433. char tmpstr[255], *at_temp, *at_buff, *at_bu2;
  434.  
  435.     for (index=0;index<=lincnt-1;index++)
  436.     {    swapped = 0;
  437.         for (jindex=index+1;jindex<=lincnt;jindex++)
  438.         {    at_buff = dirlst + (index * maxlen);
  439.             at_bu2  = dirlst + (jindex * maxlen);
  440.             flag_word = strncmp(at_buff, at_bu2, match_len);
  441.             if    ( flag_word > 0 )
  442.             {    at_temp = &tmpstr[0];
  443.                 strncpy( at_temp, at_bu2, maxlen );
  444.                 strncpy( at_bu2, at_buff, maxlen );
  445.                 strncpy( at_buff, at_temp, maxlen );
  446.                 swapped = -1;
  447.             }
  448.         }
  449.         if    (swapped == 0)
  450.             return;
  451.     }
  452. }
  453.  
  454. /*   TMLIB.C            V1.1
  455.  
  456.     Tom Mynar's Library
  457.  
  458.         CNVTIME - convert time LONGWORD to string
  459.         CNVDATE - convert date LONGWORD to string
  460.         GETSW   - extract switch and value from string
  461.         INTSTR  - convert short integer to string
  462.         LNGSTR  - convert long integer to string
  463.         POS     - locate character in string
  464.         RPTERR  - report error and text, abort program
  465.         STRFIL  - fill a string, right justified
  466.  
  467.   (c) COPYRIGHT 1986 BY THOMAS J. MYNAR
  468.   THIS SOFTWARE MAY BE COPIED AND DISTRIBUTED FREELY WITH THE
  469.   INCLUSION OF THIS NOTICE.  NO WARRANTY AND/OR USEABILITY IS
  470.   IMPLIED.
  471.  
  472. Modification History
  473.  
  474. V1.1    11-Sep-86    Correct handling of bad dates (they can kill you).
  475.  
  476. */
  477.  
  478. #include <c:gemlib.h>
  479. #include <c:stdio.h>
  480. #include <c:osbind.h>
  481.  
  482. char    month_tx[38] =  {"JanFebMarAprMayJunJulAugSepOctNovDec"};
  483.  
  484. /* Convert numeric string to right justified filled numeric string
  485.  
  486.  ( INPUT STRING CAN BE NO LONGER THAN 255 BYTES !!! )
  487.  
  488.     char    *AT_BUFF, *IN_BUFF, *FILLCHAR or literal in quotes
  489.     int    FILVAL or literal long value
  490.  
  491.     AT_BUFF = &youroutputsrtring[?];
  492.     IN_BUFF = &yournumericstring[?];
  493.     strfil( AT_BUFF, IN_BUFF, FILVAL, *FILLCHAR );
  494.     or
  495.     strfil( AT_BUFF, IN_BUFF, 0x05, "0" );
  496.  
  497.     FILVAL        is how many characters to put in front
  498.     FILLCHAR    is the character to fill with (usually 0 or <SPACE>)
  499.  
  500.     Uses a temporary string so use can pass the same string 
  501.     to both string pointers.
  502.  
  503. */
  504. extern void strfil( strptr, strnum, filval, filchr )
  505. char    *strptr, *strnum, *filchr;
  506. int    filval;
  507. {
  508. unsigned int    index, tmplen;
  509. char        tmpstr[255], *tmpptr;
  510.  
  511.     tmpptr = &tmpstr[0]; strncpy( tmpptr, strnum, filval+1 );
  512.     tmplen = filval - strlen( tmpstr );
  513.     if    ( *tmpstr == '-' )
  514.     {    if    ( *filchr != ' ' )
  515.         {    *strptr = '-'; strptr += 1; tmplen -= 1; tmpptr += 1;
  516.         }
  517.     }
  518.     for    (index=0;index<tmplen;index++)
  519.     {    *strptr = *filchr; strptr += 1;
  520.     }
  521.     for    (index=tmplen;index<=filval;index++)
  522.     {    *strptr = *tmpptr; tmpptr += 1; strptr +=1;
  523.     }
  524.     *strptr = '\0';
  525. }
  526.  
  527. /* Convert signed short integer to string.
  528.  
  529.     char        *AT_BUFF;
  530.     short int    INTEGER;
  531.  
  532.     AT_BUFF = &yourstring[pointer];
  533.     intstr( AT_BUFF, INTEGER );
  534.  
  535.     Converts up to 5 digits and a preceeding sign.
  536.  
  537. */
  538. extern void intstr( strptr, intval )
  539. char        *strptr;
  540. short int    intval;
  541. {
  542. char    tmpstr[6];
  543. int    k, j, flag, wrkint, loop_cnt;
  544.  
  545.     flag = 0; wrkint = intval; j = 0;
  546.     if    (wrkint < 0)
  547.     {    wrkint = -wrkint;
  548.     }
  549.     while    (!flag)
  550.     {    tmpstr[j]=(wrkint%10)+48;
  551.         wrkint/=10;
  552.         j++;
  553.         if    (wrkint == 0)
  554.         {    flag = -1;
  555.             if    (intval<0)
  556.             {    tmpstr[j] = '-'; j++;
  557.             }
  558.             tmpstr[j] = '\0';
  559.             loop_cnt = strlen(tmpstr)-1;
  560.             for    (k=loop_cnt; k>=0; k--)
  561.             {    *strptr = tmpstr[k]; strptr += 1;
  562.             }
  563.             *strptr = '\0';
  564.         }
  565.     }
  566. }
  567.  
  568. /* Convert signed long integer to string.
  569.  
  570.     char        *AT_BUFF;
  571.     long int    INTEGER;
  572.  
  573.     AT_BUFF = &yourstring[pointer];
  574.     lngstr( AT_BUFF, INTEGER );
  575.  
  576.     Converts up to 9 digits and a preceeding sign.
  577.  
  578. */
  579. extern void lngstr( strptr, intval )
  580. char        *strptr;
  581. long int    intval;
  582. {
  583. char    tmpstr[10];
  584. int    k, j, flag, loop_cnt;
  585. long int    wrkint;
  586.  
  587.     flag = 0; wrkint = intval; j = 0;
  588.     if    (wrkint < 0)
  589.     {    wrkint = -wrkint;
  590.     }
  591.     while    (!flag)
  592.     {    tmpstr[j]=(wrkint%10)+48;
  593.         wrkint/=10;
  594.         j++;
  595.         if    (wrkint == 0)
  596.         {    flag = -1;
  597.             if    (intval<0)
  598.             {    tmpstr[j] = '-'; j++;
  599.             }
  600.             tmpstr[j] = '\0';
  601.             loop_cnt = strlen(tmpstr)-1;
  602.             for    (k=loop_cnt; k>=0; k--)
  603.             {    *strptr = tmpstr[k]; strptr += 1;
  604.             }
  605.             *strptr = '\0';
  606.         }
  607.     }
  608. }
  609.  
  610. /* Convert long word date to string
  611.  
  612.     AT_BUFF = &youroutputbuffer[?]
  613.     PS_DATE = yourlongworddate (sysdate or directory date)
  614.     YERFLAG = yourlongwordconstant,
  615.             0 to format year 8x
  616.             not 0 to format year 198x
  617.  
  618.     cnvdate( AT_BUFF, PS_DATE, 0x?? );
  619.  
  620. */
  621. extern void cnvdate( strptr, PS_date, yerflag )
  622. long int    PS_date;
  623. int        yerflag;
  624. char        *strptr;
  625. {
  626. char        tmpstr[4], *at_bu2;
  627. unsigned short int date;
  628. short int    day, month, year;
  629.  
  630. if    (PS_date > 0x3000)
  631. {    strcpy( strptr, "00-xxx-00");
  632. }
  633. else
  634. {
  635.     date = PS_date; date >>= 9; year = date; year = year & 0xA3;
  636. /*
  637.    convert to (uns)short, shift over, move to year, AND off anything > 1999
  638. */
  639.     if    ( yerflag ) year = year + 1980;
  640.     else            year = year + 80;
  641.     date = PS_date; date <<= 7; date >>= 12; month = date;
  642.     date = PS_date; day = date & 0x1F;
  643.     at_bu2 = &tmpstr[0]; intstr( at_bu2, day );
  644.     at_bu2 = &tmpstr[0]; strfil( strptr, at_bu2, 0x02, "0" );
  645.     strptr +=2; *strptr = '-'; strptr += 1;
  646. /*
  647.    if valid month, copy string otherwise make "x"'s
  648. */
  649.     if ((month>0) && (month<13))
  650.     {    at_bu2 = &month_tx[(month-1)*3]; strncpy( strptr, at_bu2, 0x03 );
  651.     }
  652.     else
  653.     { 
  654.         strcpy( strptr, "XXX" );
  655.     }
  656.     strptr += 3; *strptr = '-'; strptr += 1;
  657.     at_bu2 = &tmpstr[0]; intstr( at_bu2, year );
  658.     at_bu2 = &tmpstr[0];
  659.     if    ( yerflag )
  660.     {    strfil( strptr, at_bu2, 0x04, " " );
  661.         strptr += 4; *strptr = '\0';
  662.     }
  663.     else
  664.     {    strfil( strptr, at_bu2, 0x02, "0" );
  665.         strptr += 2; *strptr = '\0';
  666.     }
  667. }
  668. }
  669.  
  670. /* Return time from longword
  671.  
  672.     AT_BUFF = &yourstringbuffer[?]
  673.     PS_TIME = longwordtime from system or directory call
  674.     TIMFLAG = longword constant formatting flag
  675.         If bit 0 on, return in military (HH:MM) else (HH:MM a/pm)
  676.         If bit 1 on, return seconds (HH:MM:SS) or (HH:MM:SS a/pm)
  677.  
  678. */
  679.  
  680. #define MILFORMAT 0x01
  681. #define WANTSECND 0x02
  682.  
  683. extern void cnvtime( strptr, PS_time, timflag )
  684. long int    PS_time;
  685. int        timflag;
  686. char        *strptr;
  687. {
  688. unsigned short int    time;
  689. short int        hour, minute, second, pm_flag;
  690. char            tmpstr[4], *at_bu2;
  691.  
  692.     pm_flag = 0x00; time = PS_time; time >>= 11; hour = time;
  693.     at_bu2 = &tmpstr[0]; intstr( at_bu2, hour );
  694.     if    ( ( timflag & MILFORMAT ) == 0 )
  695.     {    if    (hour > 12)
  696.         {    at_bu2 = &tmpstr[0]; pm_flag = 0xFF;
  697.             intstr( at_bu2, hour - 12 );
  698.         }
  699.     }
  700.     at_bu2 = &tmpstr[0]; strfil( strptr, at_bu2, 0x02, "0" );
  701.     time = PS_time; time <<= 5; time >>= 10; minute = time;
  702.     strptr += 2; *strptr = ':'; strptr += 1;
  703.     at_bu2 = &tmpstr[0]; intstr( at_bu2, minute );
  704.     at_bu2 = &tmpstr[0]; strfil( strptr, at_bu2, 0x02, "0" ); strptr += 2;
  705.     if    ( timflag & WANTSECND )
  706.     {    time = PS_time; second = (time & 0x1F) * 2;
  707.         at_bu2 = &tmpstr[0]; intstr( at_bu2, second );
  708.         *strptr = ':'; strptr += 1;
  709.         at_bu2 = &tmpstr[0]; strfil( strptr, at_bu2, 0x02, "0" );
  710.         strptr += 2;
  711.     }
  712.     if    ( ( timflag & MILFORMAT ) == 0 )
  713.     {    *strptr = ' '; strptr += 1;
  714.         if    ( pm_flag )
  715.         {    *strptr = 'p';
  716.         }
  717.         else
  718.         {    if    ( (hour == 12) && (minute == 0) )
  719.             {    *strptr = ' ';
  720.             }
  721.             else
  722.             {    *strptr = 'a';
  723.             }
  724.         }
  725.         strptr += 1; *strptr = 'm'; strptr += 1;
  726.     }
  727.     *strptr = '\0';
  728. }
  729.  
  730. /* Return switch and corresponding value from command line
  731.  
  732.     INT    NEXTSW;
  733.     CHAR    *AT_COMMANDLINE, *AT_SWITCH, *AT_SWITCHVALUE
  734.     INT    NOOPT, NOVAL; (external references)
  735.  
  736.     NEXTSW = getsw( AT_COMMANDLINE, AT_SWITCH, AT_SWITCHVALUE );
  737.  
  738.     if (noopt)  then no switch found
  739.         if (noval)   then no value assigned
  740.  
  741.     NEXTSW    is the byte position in AT_COMMANDLINE of the next
  742.         switch (the slash) or will be zero if no more found.
  743.  
  744.     REMEMBER that NOOPT and NOVAL must be external integers !
  745.  
  746. */
  747.  
  748. extern int getsw( arg1, arg2, arg3 )
  749. char    *arg1, *arg2, *arg3;
  750. {
  751. int        slapos, eqpos, nxtsw;
  752. extern int    noval, noopt;
  753.  
  754.     noval = 0x0; noopt = 0x0; nxtsw = 0;
  755.     slapos = pos( arg1,"/", 0x0 );
  756.     if    (slapos == 0)
  757.     {    noopt = 0xFFFF; noval = 0xFFFF;
  758.     }
  759.     else
  760.     {    eqpos = pos( arg1, "=", slapos );
  761.         if    (eqpos == 0)
  762.         {    eqpos = strlen( arg1 ) + 1;
  763.             noval = 0xFFFF;
  764.         }
  765.         nxtsw = pos( arg1, "/", slapos+1 );
  766.         if    (nxtsw == 0) nxtsw = strlen( arg1 ) + 1;
  767.         strncpy( arg2, arg1+slapos+1, eqpos - slapos - 1 );
  768.         strncpy( arg3, arg1+eqpos+1, nxtsw - eqpos - 1 );
  769.     }
  770.     if    (nxtsw >= strlen( arg1 ))
  771.         return( 0x0 );
  772.     else    return( nxtsw );
  773. }
  774.  
  775. extern int pos( srhstr, mtchcr, strtps )
  776. char    *srhstr, *mtchcr;
  777. int    strtps;
  778. {
  779. int    index, stppos, fndpos;
  780. char    str1[2], str2[2], *at_str;
  781.     str2[0] = *mtchcr; str1[1] = '\0'; at_str = srhstr+strtps;
  782.     stppos = strlen( srhstr ); fndpos = 0;
  783.     index = strtps;
  784.     while ( (fndpos == 0) && (index<stppos) )
  785.     {    if    (index<stppos)
  786.         {    str1[0] = *(srhstr+index);
  787.             if ( str1[0] == str2[0] ) fndpos = index;
  788.         index += 1;
  789.         }
  790.     }
  791.     return( fndpos );
  792. }
  793.  
  794. /* Function to dump error and exit program */
  795.  
  796. extern void rpterr( tmpstr, error )
  797. char    *tmpstr;
  798. int    error;
  799. {
  800. char    *errmsg, msgtxt[255];
  801. int    waitchar;
  802.  
  803.     Cconws( "\nError from " ); Cconws( tmpstr ); Cconws( " = " );
  804.     errmsg = &msgtxt[0]; lngstr( errmsg, error ); Cconws( errmsg );
  805.     waitchar = getch(); exit(0);
  806. }
  807. əəəəəəəəəəəəəəəəəəəəəəəəəə